from Bio import SeqIO

def fna_to_fasta(input_fna, output_fasta):
    """
    将.fna文件转换为.fasta文件。
    :param input_fna: 输入的.fna文件路径
    :param output_fasta: 输出的.fasta文件路径
    """
    with open(input_fna, "r") as input_handle, open(output_fasta, "w") as output_handle:
        # 使用SeqIO.parse读取.fna文件
        sequences = SeqIO.parse(input_handle, "fasta")
        # 将序列写入.fasta文件
        count = SeqIO.write(sequences, output_handle, "fasta")
    print(f"Converted {count} records")

# 输入和输出文件路径
input_fna = r"C:\Users\24306\OneDrive\桌面\GCA_046742065.1_ASM4674206v1_genomic.fna"
output_fasta = r"C:\Users\24306\OneDrive\桌面\GCA_046742065.1_ASM4674206v1_genomic.fasta"

# 执行转换
fna_to_fasta(input_fna, output_fasta)